﻿using System;
using System.Web.Mvc;

using Microsoft.VisualStudio.TestTools.UnitTesting;

using MvcContrib.TestHelper;

using MvcSpecFlow.Controllers;
using MvcSpecFlow.Views.Account;

using RazorGenerator.Testing;

using TechTalk.SpecFlow;

//http://www.codeproject.com/Articles/82891/BDD-using-SpecFlow-on-ASP-NET-MVC-Application
//http://blog.davidebbo.com/2011/06/precompile-your-mvc-views-using.html
//http://blog.davidebbo.com/2011/06/unit-test-your-mvc-views-using-razor.html

namespace MvcSpecFlow.Tests
{
	[Binding]
	public class RegisterUserSteps
	{
		ActionResult result;

		AccountController controller;

		[When(@"the user goes to the register user screen")]
		public void WhenTheUserGoesToTheRegisterUserScreen()
		{
			controller = new AccountController();
			result = controller.Register();

		}

		[Then(@"the register user view should be displayed")]
		public void ThenTheRegisterUserViewShouldBeDisplayed()
		{
			Assert.IsInstanceOfType(result, typeof(ViewResult));

			var vResult = (ViewResult)result;
			Assert.AreEqual(string.Empty, vResult.ViewName);

			vResult.AssertViewRendered().ForView(string.Empty); //should follow convention not pass a special view name
			
		}

		[Then(@"the view should have a username input field")]
		public void ThenTheViewShouldHaveAUsernameInputField()
		{
			var view = new Register();
			var doc = view.RenderAsHtml();
			var username = doc.GetElementbyId("UserName");
			Assert.IsNotNull(username);
		
		}
	}
}